<template>
  <div class="custom-link-button" @click="handleClick">
    <!-- 图片背景区域，铺满整个按钮 -->
    <div class="button-image" :style="{ backgroundImage: `url(${meta})` }">
      <!-- 文字描述区域 -->
      <div class="button-label">
        <h3 class="label-text">{{ label }}</h3>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CustomLinkButton',
  props: {
    label: {
      type: String,
      required: true // 背景文字
    },
    meta: {
      type: String,
      required: true // 背景图片 URL
    },
    url: {
      type: String,
      required: false, // 跳转链接
      default: '#'
    }
  },
  methods: {
    handleClick() {
      if (/^(http|https):/.test(this.url)) {
        window.open(this.url, '_blank')
      } else if (this.url) {
        this.$router.push(this.url)
      }
    }
  }
}
</script>

<style scoped>
.custom-link-button {
  display: flex;
  width: 120px; /* 按钮宽度 */
  height: 60px; /* 按钮高度 */
  border-radius: 8px; /* 圆角 */
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* 阴影效果 */
  transition:
    transform 0.3s,
    box-shadow 0.3s;
}

.custom-link-button:hover {
  transform: scale(1.05); /* 鼠标悬浮时放大 */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* 背景图片铺满整个按钮 */
.button-image {
  width: 100%;
  height: 100%;
  background-size: cover; /* 确保背景图像铺满整个按钮 */
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
}

/* 文字描述区域，绝对定位在图片上 */
.button-label {
  position: absolute;
  bottom: 8px; /* 距离底部的距离 */
  left: 8px; /* 距离左侧的距离 */
  background-color: rgba(255, 255, 255, 0.8); /* 半透明背景色 */
  padding: 2px 8px;
  border-radius: 4px; /* 文本区域圆角 */
}

.label-text {
  font-size: 12px;
  font-weight: bold;
  color: #333;
  margin: 0;
}
</style>
